<template>
  
  <div>
      <el-card class="box-card">
      <div slot="header" class="clearfix">
      <span>商品类型数据类型</span>
      <el-button style="float: right; padding: 3px 0" type="button"   @click="goAddAttr">添加</el-button>
      
      </div>
     </el-card>

      <el-table :data="attrList" border style="width: 100%">
       <el-table-column prop="id" label="编号"> </el-table-column>
        <el-table-column prop="name" label="类型名称"></el-table-column>
       <el-table-column prop="attribute_count" label="属性数量">
       </el-table-column>
       <el-table-column prop="param_count" label="参数数量"></el-table-column>
        <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="small" @click="editFun(scope.row.id,scope.row.name)"  
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="delFun(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
     </el-table>


     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="listQuery.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import {fetchProductAttrList,deleteProductAttr} from "@/api/product"
export default {
    name:'productAttr',
    data:function(){
      return {
        attrList:[],
         listQuery: {
          pageSize: 5, 
          pageNum: 1,   
      },
      total:0,
      }
    },
    mounted () {
      this.getAttrList()
    },
    methods: {
      delFun(id){
      console.log('删除触发了',id);
       this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteProductAttr({ id: id }).then((res) => {
            console.log(res);
            if (res.type == "success") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getAttrList()
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
      
      editFun(id,val){
          console.log('修改触发了',id);
          this.$router.push("/pms/productattrupdate/" + id+'/'+val);
      },
      goAddAttr(){
        this.$router.push('/pms/addAttr')
      },
      handleSizeChange(val) {
      console.log("修改每页显示的条数 触发了", val);
      this.listQuery.pageSize = val;
      this.listQuery.pageNum = 1;
      this.getAttrList();
    },
    handleCurrentChange(val) {
      console.log("修改当前页的页码 触发了", val);
      this.listQuery.pageNum = val;
      this.getAttrList();
    },
      async getAttrList(){
        const res=await fetchProductAttrList(this.listQuery)
        console.log(res);
        this.attrList=res.data,
        this.total=res.total
      }
    }
}
</script>

<style>

</style>